#include <stdio.h>
#include <stdlib.h>

#include "../card_img.h"

#define NEW_MACRO_SUPPORT

#define CARD_NUM (72)
int list[]={
	5,3,3,4,2,1,9,8,4,1,4,3,2,5,4,3,3,3,5
};
int wlist[]={
	4,-1,-1,-1,-1,-1,-1,-1,-1,1,1,2,-1,-1,-1,-1,-1,2,-1
};

char *get_string(int idx, int dir)
{
	switch(dir)
	{
			case 0:
					switch(get_card_image(idx)[2])
					{
							case ' ':
									return "TERRAIN_FARM";
							case '#':
									return "TERRAIN_CASTLE";
							case '0':
									return "TERRAIN_ROAD";
					}
					break;
			case 1:
					switch(get_card_image(idx)[14])
					{
							case ' ':
									return "TERRAIN_FARM";
							case '#':
									return "TERRAIN_CASTLE";
							case '0':
									return "TERRAIN_ROAD";
					}
					break;
			case 2:
					switch(get_card_image(idx)[22])
					{
							case ' ':
									return "TERRAIN_FARM";
							case '#':
									return "TERRAIN_CASTLE";
							case '0':
									return "TERRAIN_ROAD";
					}
					break;
			case 3:
					switch(get_card_image(idx)[10])
					{
							case ' ':
									return "TERRAIN_FARM";
							case '#':
									return "TERRAIN_CASTLE";
							case '0':
									return "TERRAIN_ROAD";
					}
					break;
	}
}
int main()
{
	int i,j;
	int count=0;
	int is_flag=0;
	int w_flag=1;
	// gen first line
	printf("static struct card _Card[TOTAL_CARD]={\n");
	for(i=0;i<CARD_TYPE_COUNT;i++)
	{
		if(i==3 || i==4)
			is_flag = 1;
		else
			is_flag = 0;
		for(j=0;j<list[i];j++)
		{
			if(wlist[i]>0)
			{
				w_flag=2;
				wlist[i]=wlist[i]-1;
			}
			else
			{
				w_flag=1;
			}
#ifdef NEW_MACRO_SUPPORT
			printf("\tSET_CARD(%d,CARD_TYPE%d,ORIEN_N,%s,%s,%s,%s,NULL,NULL,NULL,NULL,%d,%d,-1,-1)\n", 
			count, i+1, get_string(i,0),get_string(i,1),get_string(i,2),get_string(i,3),w_flag,is_flag);
#else
			printf("\t// %d\n", count+1);
			printf("\t{\n");
			printf("\t\t.card_id = %d,\n", count);
			printf("\t\t.card_type = CARD_TYPE%d,\n", i+1);
			printf("\t\t.card_orien = ORIEN_N,\n");
			printf("\t\t.terrain_type[0] = %s,\n",get_string(i,0));
			printf("\t\t.terrain_type[1] = %s,\n",get_string(i,1));
			printf("\t\t.terrain_type[2] = %s,\n",get_string(i,2));
			printf("\t\t.terrain_type[3] = %s,\n",get_string(i,3));	
			printf("\t\t.top = NULL,\n");
			printf("\t\t.right = NULL,\n");
			printf("\t\t.bottom = NULL,\n");
			printf("\t\t.left = NULL,\n");
			printf("\t\t.castle_weighting = %d,\n",w_flag);
			printf("\t\t.is_cloister = %d,\n",is_flag);
			printf("\t\t.x = -1,\n");
			printf("\t\t.y = -1,\n");
			printf("\t},\n");
#endif
			count++;
		}
	}
	printf("};\n");

	return 0;
}
